# 捕获异常
try:
    f = open("text1.txt", 'r', encoding="UTF-8")
except:
    print("ERROR1")

# 捕获指定异常
try:
    print(name)
except NameError as e:
    print("ERROR2")
    print(e)

# 捕获多个异常
# 使用元组
try:
    print(1/0)
except (NameError, ZeroDivisionError) as e:
    print("some error")
    print(e)

# 捕获全部异常(最上面的方式也是捕获全部异常)
try:
    # f = open("text1.txt", 'r', encoding="UTF-8")
    pass
except Exception as e:
    print("ERROR OCCUR")
    print(e)
else:  # 没有异常时执行
    print("hahaha, there is no error!")
finally:  # 有无异常都会执行  # 主要用来关闭文件
    print("I am always here!!!")

# 异常具有传递性, 会从最底层函数传递到最初的函数中
